package com.ysd.dao;




import java.util.List;

import javax.transaction.Transactional;

import org.apache.ibatis.annotations.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.ysd.entity.Roles;
import com.ysd.entity.User;
/**
 * 角色
 * @author CJP
 *
 */
public interface rolesDao extends JpaRepository<Roles, Integer> ,JpaSpecificationExecutor<Roles> {
	Roles getByRid(Integer id);
	 //向用户添加角色
	@Modifying
	@Query(value = "insert into userroles VALUES(?2,?1)", nativeQuery = true)
	@Transactional
	Integer saveUserrole(Integer uid,Integer rid);
	@Query(value = "select r.* from userroles u,roles r where u.rid=r.rid and u.uid=?1", nativeQuery = true)
	List<Roles>  findAll(Integer uid);
	/**
	 * 删除角色
	 * @param uId
	 * @param rId
	 */
	@Modifying
	@Query(value = "delete from userroles where uid=?1 and rid=?2", nativeQuery = true)
	@Transactional
	void delUserrole(Integer uid, Integer rid);
	/**
	 * 角色设置权限
	 */
	@Transactional
	@Modifying
	@Query(value = "INSERT INTO userroles(uid, rid) VALUES (?2, ?1) ", nativeQuery = true)
	Integer addU_R(Integer uid, Integer rid);

	@Transactional
	@Modifying
	@Query(value = "delete from userroles where uid=?1 ", nativeQuery = true)
	Integer deleteU_R(Integer uid);
}
